package com.tablefood.action;

import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.tablefood.domain.ShopProfile;
import com.tablefood.domain.ShopUser;
import com.tablefood.service.ProfileService;


public class ProfileAction extends ActionSupport {
	
	private ShopProfile profile;
	private ShopUser user;
	private String truename; //真实姓名
	private String nickname; //昵称
	private Short age;      //年龄
	private String phone;    //电话
	private String company; //公司
	
	@Resource
	private ProfileService profileService;
  
	public String showSetting(){

		HttpSession session = ServletActionContext.getRequest().getSession();
		 
		if(session.getAttribute("username")==null)
		{
			return 	ERROR;
		}else{
			
		 return SUCCESS;
		 
		}
		 
	}

	//个人详细
	public String showProfile()
	{
		
		HttpSession session = ServletActionContext.getRequest().getSession();
		
		if(session.getAttribute("username")==null)
		{
			return 	ERROR;
		}else{
			
		 String username=session.getAttribute("username").toString(); 
		 profile=(ShopProfile) profileService.searchProfileByUsername(username).get(0);
		 user=profile.getShopUser();
			
		 return SUCCESS;
		}
		
				
		
	}
	
 
	public String updataProfile(){
       
		HttpSession session = ServletActionContext.getRequest().getSession();
	 
		if(session.getAttribute("username")==null)
		{
			return 	ERROR;
		}else{
			
		 String username=session.getAttribute("username").toString(); 
		 profile=(ShopProfile) profileService.searchProfileByUsername(username).get(0);
		 profile.setTruename(truename);
		 profile.setNickname(nickname);
		 profile.setAge(age);
		 profile.setPhone(phone);
		 profile.setCompany(company);
		 profileService.updateProfile(profile);
		 }
		return "updata";
	}
	
   /***********************getter,setter********************************/
	
	
	public ShopProfile getProfile() {
		return profile;
	}

	public void setProfile(ShopProfile profile) {
		this.profile = profile;
	}

	public String getTruename() {
		return truename;
	}



	public void setTruename(String truename) {
		this.truename = truename;
	}





	public String getNickname() {
		return nickname;
	}





	public void setNickname(String nickname) {
		this.nickname = nickname;
	}





	public Short getAge() {
		return age;
	}





	public void setAge(Short age) {
		this.age = age;
	}





	public String getPhone() {
		return phone;
	}





	public void setPhone(String phone) {
		this.phone = phone;
	}





	public String getCompany() {
		return company;
	}





	public void setCompany(String company) {
		this.company = company;
	}

  
 
	public ShopUser getUser() {
		return user;
	}
 
	public void setUser(ShopUser user) {
		this.user = user;
	}

}
